package main

import "fmt"

func longestMountain(A []int) int {
	length := 0
	for i := 1; i < len(A)-1; i++ {
		if A[i-1] < A[i] && A[i] > A[i+1] {
			lenTemp := getLength(A, i, i)
			if length < lenTemp {
				length = lenTemp
			}
		}
	}
	return length
}

func getLength(A []int, left, right int) int {
	fmt.Printf("left = %d, right = %d\n", left, right)
	for left > 0 && A[left-1] < A[left] {
		left--
	}
	for right < len(A)-1 && A[right] > A[right+1] {
		right++
	}
	fmt.Printf("left = %d, right = %d\n", left, right)
	return right - left + 1
}

func main() {
	arr := []int{2, 1, 4, 7, 3, 2, 5}
	fmt.Println(arr)
	length := longestMountain(arr)
	fmt.Printf("length = %d\n", length)
}
